library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Char_ROM is
	generic(
		N: integer:= 6;
		M: integer:= 3;
		W: integer:= 8
	);
	port(
		char_address: in std_logic_vector(5 downto 0);
		font_row, font_col: in std_logic_vector(M-1 downto 0);
		rom_out: out std_logic
	);
end;

architecture p of Char_ROM is
	subtype tipoLinea is std_logic_vector(0 to W-1);

	type char is array(0 to W-1) of tipoLinea;
	constant A: char:= (
								"01111110",
								"10000001",
								"10000001",
								"10000001",
								"10000001",
								"10000001",
								"11111111",
								"00000000"
						);	
	constant B: char:= (
								"00001000",
								"00011000",
								"00111000",
								"00011000",
								"00011000",
								"00011000",
								"00011000",
								"00011000"
						);
	
		constant C: char:= (
								"01111110",
								"00000001",
								"00000001",
								"01111110",
								"11111100",
								"11000000",
								"11000000",
								"01111110"
						);
						
		constant D: char:= (
								"11111110",
								"00000001",
								"00000001",
								"01111110",
								"00000001",
								"00000001",
								"11111111",
								"00000000"
						);
						
		constant E: char:= (
								"10000001",
								"10000001",
								"10000001",
								"10000001",
								"01111111",
								"00000001",
								"00000001",
								"00000001"
						);	
						
		constant F: char:= (
								"01111111",
								"10000000",
								"10000000",
								"01111110",
								"00000001",
								"00000001",
								"00000001",
								"11111110"
						);		
													
		constant G: char:= (
								"01111111",
								"10000000",
								"10000000",
								"01111110",
								"10000001",
								"10000001",
								"10000001",
								"11111110"
						);
						
		constant H: char:= (
								"01111110",
								"00000001",
								"00000001",
								"00000001",
								"00000001",
								"00000001",
								"00000001",
								"00000001"
						);	
						
		constant I: char:= (
								"01111110",
								"10000001",
								"10000001",
								"01111110",
								"10000001",
								"10000001",
								"10000001",
								"01111110"
						);	
		constant J: char:= (
								"01111110",
								"10000001",
								"10000001",
								"10000001",
								"01111111",
								"00000001",
								"00000001",
								"00000001"
						);	
		constant V: char:= (
								"11000011",
								"01100011",
								"01100110",
								"00110110",
								"00111100",
								"00011000",
								"00000000",
								"00000000"
						);																												
	
		constant coma: char:= (
								"00000000",
								"00000000",
								"00000000",
								"00000000",
								"00000000",
								"00011000",
								"00010000",
								"00100000"
						);	
	type memo is array(0 to 255) of tipoLinea;
	signal RAM: memo:= (
								0 => A(0), 1 => A(1), 2 => A(2), 3 => A(3), 4 => A(4), 5 => A(5), 6 => A(6), 7 => A(7),
								8 => B(0), 9 => B(1), 10 => B(2), 11 => B(3), 12 => B(4), 13 => B(5), 14 => B(6), 15 => B(7),
								16 => C(0), 17 => C(1), 18 => C(2), 19 => C(3), 20 => C(4), 21 => C(5), 22 => C(6), 23 => C(7),
								24 => D(0), 25 => D(1), 26 => D(2), 27 => D(3), 28 => D(4), 29 => D(5), 30 => D(6), 31 => D(7),
								32 => E(0), 33 => E(1), 34 => E(2), 35 => E(3), 36 => E(4), 37 => E(5), 38 => E(6), 39 => E(7),
								40 => F(0), 41 => F(1), 42 => F(2), 43 => F(3), 44 => F(4), 45 => F(5), 46 => F(6), 47 => F(7),
								48 => G(0), 49 => G(1), 50 => G(2), 51 => G(3), 52 => G(4), 53 => G(5), 54 => G(6), 55 => G(7),
								56 => H(0), 57 => H(1), 58 => H(2), 59 => H(3), 60 => H(4), 61 => H(5), 62 => H(6), 63 => H(7),
								64 => I(0), 65 => I(1), 66 => I(2), 67 => I(3), 68 => I(4), 69 => I(5), 70 => I(6), 71 => I(7),
								72 => J(0), 73 => J(1), 74 => J(2), 75 => J(3), 76 => J(4), 77 => J(5), 78 => J(6), 79 => J(7),
								80 => V(0), 81 => V(1), 82 => V(2), 83 => V(3), 84 => V(4), 85 => V(5), 86 => V(6), 87 => V(7),
								88 => coma(0),  89 => coma(1), 90=> coma(2),91 => coma(3),  92=> coma(4), 93 => coma(5),  94 => coma(6), 95 => coma(7),
																
								96 to 255 => "00000000"
							);

	signal char_addr_aux: std_logic_vector(8 downto 0);
	
begin

	char_addr_aux <= char_address & font_row;
	rom_out <= RAM(conv_integer(char_addr_aux))(conv_integer(font_col));

end;